<%--
  Created by IntelliJ IDEA.
  User: Cc
  Date: 2020/12/30
  Time: 16:51
  To change this template use File | Settings | File Templates.
--%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" +
            request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="<%=basePath%>static/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="<%=basePath%>static/css/font.css">
    <link rel="stylesheet" href="<%=basePath%>static/css/xadmin.css">
    <script type="text/javascript" src="<%=basePath%>static/js/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="<%=basePath%>static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="<%=basePath%>static/js/xadmin.js"></script>
</head>

<body>
<div class="x-body">
    <form class="layui-form" method="post">
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>姓名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="age" class="layui-form-label">
                年龄
            </label>
            <div class="layui-input-inline">
                <input type="text" id="age" name="age"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="sex" class="layui-form-label">
                性别
            </label>
            <div class="layui-input-inline">
                <input type="text" id="sex" name="sex"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="appointmentDate" class="layui-form-label">
                预约日期
            </label>
            <div class="layui-input-inline">
                <input type="text" id="appointmentDate" name="appointmentDate"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="doctor" class="layui-form-label">
                预约医生
            </label>
            <div class="layui-input-inline">
                <input type="text" id="doctor" name="doctor"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="symptom" class="layui-form-label">
                症状
            </label>
            <div class="layui-input-inline">
                <input type="text" id="symptom" name="symptom"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button class="layui-btn" id="L_repass" type="button" onclick="doUpdate()">
                修改
            </button>
        </div>
    </form>
</div>

<script>
    $(document).ready(function () {
        $("#name").val(localStorage.getItem("name"))
        $("#age").val(localStorage.getItem("age"))
        $("#sex").val(localStorage.getItem("sex"))
        $("#appointmentDate").val(localStorage.getItem("appointmentDate"))
        $("#doctor").val(localStorage.getItem("doctor"))
        $("#symptom").val(localStorage.getItem("symptom"))
    })

    function doUpdate() {
        $.ajax({
            url: "../appointment/appointmentEdit",
            type: "post",
            dataType: "json",
            data: {
                "appointId":localStorage.getItem("appointId"),
                "name": $("#name").val(),
                "age": $("#age").val(),
                "sex": $("#sex").val(),
                "appointmentDate": $("#appointmentDate").val(),
                "doctor": $("#doctor").val(),
                "symptom": $("#symptom").val(),

            },
            success: function (data) {
                console.log(data);
                if (data.msg == "修改成功") {
                    layer.alert("修改成功", {icon: 6}, function () {
                        let index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.location.reload();
                    })
                } else {
                    layer.alert("修改失败", {icon: 5}, function () {
                        let index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.location.reload();
                    })
                }
            },
            error: function () {
                alert("错误")
            }
        })
    }

</script>
</body>

</html>